// easy

// 给定一个二叉树，将其进行左右翻转

// 从根节点开始遍历，然后从叶子节点向上递归交换左右子树位置

function invertTree(root) {
    if (!root) {
        return root
    }
    let left = invertTree(root.left)
    let right = invertTree(root.right)
    root.left = right
    root.right = left
    return root
}

const root = {
    val: "A",
    left: {
        val: "B",
        left: {
            val: "D",
        },
        right: {
            val: "E",
        },
    },
    right: {
        val: "C",
        right: {
            val: "F",
        },
    },
};

console.log(invertTree(root))